var ProgressBar = require("progress");

class Bar {
	start() {
		this.instance = new ProgressBar(
			"全力下载中...[:bar] :rate/bps :percent :etas",
			{
				total: 50,
			}
		);
		const _this = this;
		this.timer = setInterval(function () {
			if (_this.instance.curr < 30) _this.instance.tick(0.8);
			else if (_this.instance.curr < 40) _this.instance.tick(0.4);
			else if (_this.instance.curr < 47) _this.instance.tick(0.1);
			else if (_this.instance.curr < 49) _this.instance.tick(0.00001);
		}, 100);
	}
	end(massage) {
		while (!this.instance.complete) {
			this.instance.tick(1);
		}
		console.log(`\n${massage}`);
		clearInterval(this.timer);
	}
}
module.exports = new Bar();
